package com.itheima.activiti.controller.system;

import com.itheima.activiti.auth.annotation.IgnoreToken;
import com.itheima.activiti.common.R;
import com.itheima.activiti.dto.system.LoginDTO;
import com.itheima.activiti.service.system.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/auth")
@Api(tags = "系统认证接口")
public class AuthController {

    @Autowired
    private UserService userService;

    @ApiOperation("登录认证")
    @GetMapping(value = "/login")
    @IgnoreToken
    public R<LoginDTO> login(String user, String password) {
        LoginDTO loginDTO = userService.login(user, password);
        if (loginDTO == null) {
            return R.error("用户名或密码错误！");
        }
        return R.success(loginDTO);
    }
}
